package com.doitedu.day04.funcs

/**
 * @Date 22.6.23
 * @Created by HANGGE
 * @Description
 *  reduce 聚合  默认的计算逻辑是从左到右 依次计算
 */
object _05ReduceRight {
  def main(args: Array[String]): Unit = {
    val  ls = List[Int](1,2,3,4,5,6)
    // (5,6)  === 5-6  -1
    //  1-(2-(3-(4-(5-6)
    println(ls.reduceRight((x1, x2) => x1 - x2))

 /*   println(ls.reduceLeft((x1, x2) => x1 + x2))
    println(ls.reduceLeft(_ + _))
    val arr = Array("a" , "v" , "f" , "l")
    println(arr.reduceLeft(_ + " " + _))*/
    val arr = Array("a" , "v" , "f" , "l")
    println(arr.reduceLeft(_ + " " + _))
    println(arr.reduceRight(_ + ":" + _))

  }

}
